﻿using System;
using System.Text;
using System.Data;

using LTJ.Common.Generic;
using LTJ.Entity;
using LTJ.Common;
using LTJ.Config;

namespace LTJ.Data.DataProvider
{
    /// <summary>
    /// 授权信息数据操作
    /// </summary>
    public class Routes
    {
        /// <summary>
        /// 创建航线授权信息
        /// </summary>
        public static int CreateRoute(RouteInfo rinfo)
        {
            return DatabaseProvider.GetInstance().CreateRoute(rinfo);
        }
        public static int AddRoute(DataTable dt)
        {
            return DatabaseProvider.GetInstance().AddRoute(dt);
        }
        /// <summary>
        /// 判断航线重复授权
        /// </summary>
        /// <param name="cid">公司ID</param>
        /// <param name="tcode">航线Code</param>
        /// <param name="bcode">船公司code</param>
        public static bool ExistReRoute(int cid, string tcode, string bcode)
        {
            return DatabaseProvider.GetInstance().ExistReRoute(cid, tcode, bcode);
        }

        /// <summary>
        /// 根据ID获取授权信息
        /// </summary>
        public static RouteInfo GetRountByID(int id)
        {
            return LoadSingleRount(DatabaseProvider.GetInstance().GetRountByID(id));
        }
        /// <summary>
        /// 根据ID获取授权信息
        /// </summary>
        public static RouteInfo GetRountByStr(string strWhere)
        {
            return LoadSingleRount(DatabaseProvider.GetInstance().GetRountByStr(strWhere));
        }
        /// <summary>
        /// 根据ID获取授权信息
        /// </summary>
        public static DataTable GetRountTabByStr(string strWhere)
        {
            return DatabaseProvider.GetInstance().GetRountTabByStr(strWhere);
        }

        /// <summary>
        /// 根据条件获取航线信息
        /// </summary>
        public static List<RouteInfo> GetRountList(string strWhere)
        {
            return LoadRountCollection(DatabaseProvider.GetInstance().GetRountList(strWhere));
        }

        /// <summary>
        /// 获取航线授权信息分页
        /// </summary>
        public static DataTable GetRoutesByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype)
        {
            return DatabaseProvider.GetInstance().GetRoutesByPage(pageindex, pagesize, condition, ordercolumn, ordertype);
        }

        /// <summary>
        /// 根据条件获取航线授权信息集合数量
        /// </summary>
        public static int GetRoutesCount(string conditions)
        {
            return DatabaseProvider.GetInstance().GetRoutesCount(conditions);
        }

        /// <summary>
        /// 修改航线授权信息
        /// </summary>
        public static int UpdateRoute(RouteInfo rinfo)
        {
            return DatabaseProvider.GetInstance().UpdateRoute(rinfo);
        }
        /// <summary>
        /// 删除航线授权信息
        /// </summary>
        /// <param name="ids">航线授权id组合</param>
        /// <returns></returns>
        public static int DelRoutes(string ids)
        {
            return DatabaseProvider.GetInstance().DelRoutes(ids);
        }

        #region helper
        public static RouteInfo LoadSingleRount(IDataReader reader)
        {
            RouteInfo _info = null;
            if (reader.Read())
            {
                _info = new RouteInfo();
                _info.id = TypeConverter.ObjectToInt(reader["id"], 0);
                _info.cid = TypeConverter.ObjectToInt(reader["cid"], 0);
                _info.tcode = reader["tcode"].ToString();
                _info.tname = reader["tname"].ToString();
                _info.bcode = reader["bcode"].ToString();
                _info.bname = reader["bname"].ToString();
                _info.creater = reader["creater"].ToString();
                _info.createdate = Utils.GetStandardDateTime(reader["createdate"].ToString());
            }
            reader.Close();
            return _info;
        }

        public static List<RouteInfo> LoadRountCollection(IDataReader reader)
        {
            List<RouteInfo> rinfolist = new List<RouteInfo>();

            while (reader.Read())
            {
                RouteInfo _info = new RouteInfo();
                _info.id = TypeConverter.ObjectToInt(reader["id"], 0);
                _info.cid = TypeConverter.ObjectToInt(reader["cid"], 0);
                _info.tcode = reader["tcode"].ToString();
                _info.tname = reader["tname"].ToString();
                _info.bcode = reader["bcode"].ToString();
                _info.bname = reader["bname"].ToString();
                _info.creater = reader["creater"].ToString();
                _info.createdate = Utils.GetStandardDateTime(reader["createdate"].ToString());
                rinfolist.Add(_info);
            }
            reader.Close();
            return rinfolist;
        }
        #endregion
    }
}
